package com.qf.zwy.office.conteroller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.office.common.base.result.ResponseResult;
import com.qf.office.common.base.result.ResultStatus;
import com.qf.zwy.office.common.qo.AddTrainingQo;
import com.qf.zwy.office.common.qo.TrainingQo;
import com.qf.zwy.office.common.qo.UpdateTrainingQo;
import com.qf.zwy.office.common.vo.TrainingVo;
import com.qf.zwy.office.entity.Training;
import com.qf.zwy.office.service.TrainingService;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.data.repository.query.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.naming.spi.ResolveResult;
import javax.validation.constraints.Min;
import javax.websocket.server.PathParam;

/**
 * @author 子未语
 */
@RestController
@Api(tags = "培训接口")
@RequestMapping("/training")
@Validated
public class TrainingController {

    @Resource
    private TrainingService trainingService;

    @ApiOperation("进行分页查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "trainingQo", value = "查询条件"),
            @ApiImplicitParam(name = "size", value = "页数"),
            @ApiImplicitParam(name = "page", value = "尺寸")})
    @PostMapping("/page")
    public ResponseResult<IPage<TrainingVo>> selectAll(@RequestBody TrainingQo trainingQo,
                                                       @RequestParam(defaultValue = "1") Integer size,
                                                       @RequestParam(defaultValue = "3") Integer page) {
        return ResponseResult.success(trainingService.selectAll(trainingQo, size, page));
    }

    @ApiOperation("查询单个培训")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "查询的id")})
    @PostMapping("/{id}")
    public ResponseResult<TrainingVo> selectOne(@PathVariable Integer id) {
        return ResponseResult.success(trainingService.selectOne(id));
    }

    @ApiOperation("添加单个培训计划")
    @ApiImplicitParams({@ApiImplicitParam(name = "addTrainingQo", value = "添加的数据")})
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody AddTrainingQo addTrainingQo) {
        return ResponseResult.success(trainingService.add(addTrainingQo));
    }

    @ApiOperation("修改培训的信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "updateTrainingQo", value = "修改的数据")})
    @PostMapping("/update")
    public ResponseResult<Integer> update(@RequestBody UpdateTrainingQo updateTrainingQo) {
        return ResponseResult.success(trainingService.update(updateTrainingQo));
    }
}
